package com.yuxinmuyu.sports_management.controller.publicController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuxinmuyu.sports_management.bean.entiy.SportsScore;
import com.yuxinmuyu.sports_management.bean.request.GetSportsProjectRequest;
import com.yuxinmuyu.sports_management.bean.request.GetSportsScoreIDRequest;
import com.yuxinmuyu.sports_management.bean.request.GetSportsScoreInfoRequest;
import com.yuxinmuyu.sports_management.bean.request.GetSportsScoreRequest;
import com.yuxinmuyu.sports_management.bean.response.GetSportsScoreResponse;
import com.yuxinmuyu.sports_management.exception.R;
import com.yuxinmuyu.sports_management.service.SportsScoreService;
import com.yuxinmuyu.sports_management.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/SportsScore")
@Api(value = "运动项目项目成绩",tags = {"运动项目项目成绩"})
public class SportsScoreController {
    @Resource
    SportsScoreService sportsScoreService;

    @ApiOperation("添加运动会成绩")
    @PostMapping("/adm/addSportsScore")
    public R<?> addSportsScore(@RequestBody @Validated GetSportsScoreRequest request){
        sportsScoreService.addSportsScore(request);
        return R.success("添加成功!");
    }

    @ApiOperation("根据ID删除运动会成绩")
    @PostMapping("/adm/deleteSportsScore")
    public R<?>deleteSportsScore(@RequestBody @Validated GetSportsScoreIDRequest request){
        sportsScoreService.deleteSportsScore(request);
        return R.success("删除成功！");
    }

    @ApiOperation("根据ID更新运动会成绩")
    @PostMapping("/adm/updateSportsScore")
    public R<?>updateSportsScore(@RequestBody @Validated SportsScore sportsScore){
        sportsScoreService.updateSportsScore(sportsScore);
        return R.success("更新成功！");
    }

    @ApiOperation("查询运动会成绩")
    @PostMapping("/adm/selectSportsScore")
    public R<Page<GetSportsScoreResponse>>selectSportsScore(@RequestBody @Validated GetSportsScoreInfoRequest request){
        return R.success(sportsScoreService.selectSportsScore(request));
    }

    @ApiOperation("学校查询个人运动会成绩")
    @PostMapping("/selectSportsScore")
    public R<Page<GetSportsScoreResponse>>selectSportsScoreByID(@RequestBody @Validated GetSportsScoreInfoRequest request){
        request.setKeyword(UserUtil.getUserId());
        return R.success(sportsScoreService.selectSportsScore(request));
    }

    @ApiOperation("导出运动会成绩信息")
    @PostMapping("/adm/export")
    public void export(@RequestBody @Validated GetSportsScoreInfoRequest request, @ApiIgnore HttpServletResponse response) throws IOException {
        sportsScoreService.export(request,response);
    }
}
